Repository navigation
Let a freestanding object compare text - #37
Merged
Merged
Conversation
The allocation path was routed through the native runtime on this branch and the comparison path was not, so a freestanding object could concatenate but could not compare: `==` on text emitted a call to `strcmp`, which such an object has no libc to resolve and whose presence its own import surface forbids. That is the same defect the concatenation helper had before -- it imported strlen, memcpy and calloc unconditionally -- in a different operation. It was found from the consumer side, which is the only place it could have been found. A vessel wanted to recognise a word in a line its kernel delivered, and the import check refused the object. Three sites emitted strcmp: the text comparison operators, a variant tag against one expected string, and a variant tag against an allowed set. All three now ask one function for the symbol, so a fourth site cannot be routed correctly in two places and wrongly in a third. The locals are renamed with it, because a reader seeing `strcmp_fn` would reasonably assume libc. The hook is nyrt_str_compare, and its contract is narrower than strcmp's: only the sign is defined, because that is all generated code reads. Native text is NUL-free, so unsigned-byte order matches the interpreter's. A null is not a text value, and the runtime orders a null before any non-null rather than reading through one, which keeps the comparison total for inputs generated code should never produce. It is defined in the hosted runtime too, for the same reason mem_copy and str_length are: otherwise an object emitted with --freestanding could only ever link against the freestanding archive, and which runtime to link would stop being the host's choice. Comparison allocates nothing, so this is a fourth conditional hook rather than a fourth allocation hook. Five always, three if the program allocates, one if it compares text -- each required only by the construct that uses it, so the import surface still states what a program does rather than what the language can do. Measured both ways from one source. Hosted imports strcmp and no runtime comparison hook; freestanding imports nyrt_str_compare and no libc name at all. Then linked against the archive and run, because an import list cannot show the answers are right: a comparison that said "equal" to everything would link and satisfy any symbol check. A program comparing "alpha", "beta" and a second "alpha" returns what Ny returned, so equality, inequality and ordering all hold. nil.native-symbol-surface goes from 18 checks to 23 and nil.freestanding-runtime from 12 to 14. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found from the consumer side, which is the only place it could have been found: an Anomalous vessel wanted to recognise a word in a line its kernel delivered, and the object would not link.
==on text emitted a call tostrcmp.That is the same defect the concatenation helper had before the last branch — it imported
strlen,memcpyandcallocunconditionally — in a different operation. The allocation path was routed through the native runtime and the comparison path was not, so a freestanding object could concatenate but could not compare, and the failure was not a diagnostic: it was a libc import that a consumer's own symbol check rejects at link time, a long way from where the mistake is.What changed
Three sites emitted
strcmp: the text comparison operators, a variant tag against one expected string, and a variant tag against an allowed set. All three now ask one function for the symbol, so a fourth site cannot be routed correctly in two places and wrongly in a third. The locals are renamed with it, because a reader seeingstrcmp_fnwould reasonably assume libc.The hook is
nyrt_str_compare, and its contract is deliberately narrower thanstrcmp's: only the sign is defined, because that is all generated code reads. Native text is NUL-free, so unsigned-byte order matches the interpreter's. A null is not a text value, and the runtime orders a null before any non-null rather than reading through one, which keeps the comparison total for inputs generated code should never produce.It is defined in the hosted runtime too, for the same reason
nyrt_mem_copyandnyrt_str_lengthare: otherwise an object emitted with--freestandingcould only ever link against the freestanding archive, and which runtime to link would stop being the host's choice.Comparison allocates nothing, so this is a fourth conditional hook rather than a fourth allocation hook. Five always, three if the program allocates, one if it compares text — each required only by the construct that uses it, so the import surface still states what a program does rather than what the language can do.
Measured, not asserted
The same source, emitted both ways:
Then linked against the archive and run, because an import list cannot show that the answers are right — a comparison that said "equal" to everything would link and satisfy any symbol check. A program comparing
"alpha","beta"and a second"alpha"returns what Ny returned, so equality, inequality and ordering all hold.nil.native-symbol-surfacegoes from 18 checks to 23 andnil.freestanding-runtimefrom 12 to 14. Full suite: 574 of 574 pass, re-run on freshly built binaries after the rename (3 environmental skips: PostgreSQL ×2, UI display).Note for the consumer side
Anomalous cannot use this until a generation carrying it is built and that repository re-pins. Its vessel currently selects a test run through a cell the host writes, which is a workaround for this defect and can be simplified once the pin moves. Re-pinning is a deliberate act there — the pin is the evidence for a qualification — so it is not done here.
🤖 Generated with Claude Code